package com.ymatou.iapi.godfreightmgr.testcase;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.GodfreightmgrService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymatou.iapi.godfreightmgr.parameter.CreateCollectionGoodsAddressBean;
import com.ymatou.iapi.godfreightmgr.parameter.GetAddressNameListBean;
import com.ymatou.iapi.godfreightmgr.service.GetAddressNameListCall;


/**
 * 自提点列表 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetAddressNameList {
	private static com.ymatou.iapi.godfreightmgr.parameter.GetAddressNameListBean GetAddressNameListBean;
	private static GetAddressNameListCall GetAddressNameListCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("自提点列表");
	}

	@Before
	public void caseUp() {
		 GetAddressNameListBean = new GetAddressNameListBean();
		 GetAddressNameListCall = new GetAddressNameListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult( GetAddressNameListCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GetAddressNameList_001() {
		Logger.start(true, "查询自提点列表成功");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			// 开启运营
			GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);

			Map<String, CreateCollectionGoodsAddressBean> m = new HashMap<String, CreateCollectionGoodsAddressBean>();
			List<Integer> addressIds=new ArrayList<Integer>();
			for (int i = 0; i < 2; i++) {
				// 添加一个自提地址
				CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService
						.initCreateCollectionGoodsAddressBean(mchId_channl);
				int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
				m.put(createcollectiongoodsaddressBean.getAddressName(), createcollectiongoodsaddressBean);
				addressIds.add(addressId);
			}
			 GetAddressNameListBean.setSellerId(mchId_channl);
			 GetAddressNameListBean.setAddressIds(addressIds);
			 GetAddressNameListCall.setData( GetAddressNameListBean);
			 GetAddressNameListCall.callService();
			Logger.verifyEquals("200",GetAddressNameListCall.getString("code"), "验证code");
			GetAddressNameListCall.getJsonObject().get("data").getAsJsonArray().forEach(data->{
				String address = data.getAsString();
				Logger.verifyEquals(true, m.get(address)!=null, "验证存在");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

}